package mhl.service;

import mhl.dao.DiningTableDAO;
import mhl.domain.DiningTable;

import java.util.List;

/**
 * @author DCSGO
 * @version 1.0
 */
public class DiningTableService {
    private final DiningTableDAO diningTableDAO = new DiningTableDAO();

    public boolean cleanDiningTable(int id) {
        String sql = "update diningTable set state = '空',orderName = ' ',orderTel = ' ' where id = ?";
        return diningTableDAO.update(sql, id) > 0;
    }

    public boolean updateDiningTableState(int id, String state) {
        String sql = "update diningTable set state = ? where id = ?";
        return diningTableDAO.update(sql, state, id) > 0;
    }

    public List<DiningTable> getAllDins() {
        String sql = "select * from diningTable";
        return diningTableDAO.queryMulti(sql, DiningTable.class);
    }

    public DiningTable getDingById(int id) {
        String sql = "select * from diningTable where id = ?";
        return diningTableDAO.querySingle(sql, DiningTable.class, id);
    }

    public boolean orderDingTable(int id, String orderName, String orderTel) {
        String sql = "update diningTable set state = '已被预定',orderName = ?,orderTel = ? where id = ?";
        return diningTableDAO.update(sql, orderName, orderTel, id) > 0;
    }
}
